
/* 日期格式化 */
export function formatTime(time, format = '') {
    let str = '';

    if (!time || time == 0) {
        str = '';
    } else {
        let date = new Date(Number(time));
        let y = date.getFullYear();
        let m = (date.getMonth() + 1).toString().padStart(2, '0');
        let d = date.getDate().toString().padStart(2, '0');

        str = y + '-' + m + '-' + d;
    }

    return str;
}

/*-------------------------------------------------------------------------------------
 | 系统设置
 |-------------------------------------------------------------------------------------
 */
/**
 * 菜单管理-类型，1-分类，2-菜单，3-按钮，4-动作
 */
export function systemMenuTypeToStr(value) {
    let str = '';

    if (value == 1) {
        str = '分类';
    } else if (value == 2) {
        str = '菜单';
    } else if (value == 3) {
        str = '按钮';
    } else if (value == 4) {
        str = '动作';
    }

    return str;
}
/**
 * 用户角色
 */
export function systemUserRole(id, roles = []) {
    let str = '';

    roles.forEach((item) => {
        if (item.id == id) str = item.name;
    });

    return str;
}


/* 转义?<>/\等符号 */
export function unescape(html) {
    return html
        .replace(html ? /&(?!#?\w+;)/g : /&/g, '&amp;')
        .replace(/&lt;/g, "<")
        .replace(/&gt;/g, ">")
        .replace(/&quot;/g, "\"")
        .replace(/&#39;/g, "\'");
}
